
'use strict';
function qs(name){ const m = location.search.match(new RegExp('[?&]'+name+'=([^&]+)')); return m ? decodeURIComponent(m[1]) : ''; }
function makeTagHref(label){ return 'playlist.html?q=' + encodeURIComponent(label.split(' ')[0]); }
function renderCategory(type){
  const el = document.getElementById('tag-section'); el.innerHTML = '';
  const map = { genres:'流派 Genres', moods:'情绪 Moods', instruments:'乐器 Instruments', scenes:'场景 Scenes' };
  const list = (TAG_DATA[type]||[]);
  const panel = document.createElement('div');
  panel.className = 'tag-panel';
  panel.innerHTML = `
    <div class="panel-head">
      <h2>${map[type] || '合集'}</h2>
      <div class="count">${list.length} 个标签</div>
    </div>
    <div class="tag-list" id="tag-list"></div>`;
  el.appendChild(panel);
  const listEl = panel.querySelector('#tag-list');
  list.sort((a,b)=>a.localeCompare(b,'zh-Hans'));
  list.forEach((label, idx) => {
    const a = document.createElement('a');
    a.href = makeTagHref(label);
    a.setAttribute('data-i', String(idx+1));
    a.innerHTML = `<span class="badge">${idx+1}</span><span class="name">${label}</span>`;
    listEl.appendChild(a);
  });
  const title = document.getElementById('page-title'); if (map[type]) title.textContent = map[type] + ' · 全部标签';
}
(function(){ const type = qs('type') || 'genres'; renderCategory(type); })();
